package com.zheng.upms.rpc.task;

import com.zheng.upms.job.AsyncJobFactory;
import com.zheng.upms.rpc.api.UpmsScheduleJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 项目启动时初始化定时任务
 * @author cuiP
 * Created by JK on 2017/5/9.
 */
@Component
public class ScheduleJobListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(AsyncJobFactory.class);

    @Resource
    private UpmsScheduleJobService upmsScheduleJobService;

    /**
     * 项目启动时初始化
     */
    @PostConstruct
    public void init() {

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("初始化定时任务...,开始");
        }

        try {
            upmsScheduleJobService.initScheduleJob();
        } catch (Exception e) {
            LOGGER.error("初始化定时任务失败");
        }

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("初始化定时任务...,完成");
        }
    }
}
